package cn.edu.gcu.giftems.pojos;

import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * TODO: Description here...
 *
 * @author ZhengHQ
 * @create 2018-10-07
 * @see
 */
public class Order {
    /** id **/
    private int id;
    private Date orderDate;
    private int status;
    private User user;
    private Set<OrderItem> orderItems = new HashSet<OrderItem>();
    private int userId;
    private String userName;

    public Order() {
    }

    public Order( Date orderDate, int status, User user) {
        this.orderDate = orderDate;
        this.status = status;
        this.user = user;
    }

    public Order(int id, Date orderDate, int status, int userId, String userName) {
        this.id = id;
        this.orderDate = orderDate;
        this.status = status;
        this.userId = userId;
        this.userName =userName;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Date getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(Date orderDate) {
        this.orderDate = orderDate;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Status getStatus() {
        return Status.fromCode(status);
    }

    public void setStatus(Status status) {
        this.status = status.getCode();
    }

    public Set<OrderItem> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(Set<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }

    @Override
    public String toString() {
        return "Order{" +
                "id=" + id +
                ", orderDate=" + orderDate +
                ", status=" + status +
                '}';
    }

    public enum Status {
        SUCCESS(1), CLOSED(2), DAIZHIFU(3), YIZHIFU(4), DAIFAHUO(5), YIFAHUO(6), TUIHUO(7),;

        int code;

        Status(int code) {
            this.code = code;
        }

        public static Status fromCode(int code) {
            switch (code) {
                case 1:
                    return SUCCESS;
                case 2:
                    return CLOSED;
                case 3:
                    return DAIZHIFU;
                case 4:
                    return YIZHIFU;
                case 5:
                    return DAIFAHUO;
                case 6:
                    return YIFAHUO;
                case 7:
                    return TUIHUO;
                default:
                    throw new IllegalArgumentException();
            }
        }

        @Override
        public String toString() {
            switch (code) {
                case 1:
                    return "交易成功";
                case 2:
                    return "交易关闭";
                case 3:
                    return "待支付";
                case 4:
                    return "已支付";
                case 5:
                    return "待发货";
                case 6:
                    return "已发货";
                case 7:
                    return "退货中";
            }
            return null;
        }

        public int getCode() {
            return code;
        }
    }
}
